
<template>
	<!-- 添加弹框 -->
	<el-dialog title="" visible :show-close="false" :append-to-body="true" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index:10;"></i>
	    <div class="bt">新增盘点</div>
	     <el-form label-width="100px" class="form">
	     <el-form-item label="物品名称">
			<el-input v-model="vwpid"  placeholder="请选择物品名称" icon="add" class="input"v-if="false" ></el-input>
			<el-input v-model="vwpidmc" placeholder="请选择物品名称" icon="add" class="input" :readonly="true"></el-input>
			<el-button size='small'  @click="componentsShow('xzwp')" >选择</el-button>
		</el-form-item>
		<el-form-item label="说明">
			<el-input v-model="vnote"  type="textarea" :rows="4" placeholder="请输入盘点原因" icon="add" class="input1"></el-input>
		</el-form-item>
		<Xzwplist v-if="portComponents.xzwp.toggle"  @close="componentsHide"  :data="portComponents.xzwp.data" :params="this.wpfl"></Xzwplist>
        <div class="an" style="text-align: center;">
		<el-button type="primary" class="submit" @click="submit">添加</el-button>
		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
		</div>
	</el-form>

	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	import Xzwplist from '../bs/xzwp'

	export default {
		props: ['params'],
		 components: { Xzwplist},
		data() {
			return {
				wpfl:'',
				showchoselist:false,
				vwpid: '',
				vwpidmc:'',
				vlsid: '',
				vlysl: '',
				vnote: '',
				// vlyckid: '',
				comboxlist:[],
				comboxlistck:[],
				dialogTableVisible: true,
				portComponents: {
						xzwp : {
								type: 'xzwp',
								toggle: false,
								params: '',
								data: {}
						}
				},
			}
		},
		 created(){
//		 			 	alert(this.params)
		 	this.wpfl=this.params;
	 },
		methods: {
			submit() {
				//检测
				this.$store.state.loading = true;
			    if(!this.vwpid) {
					this.$message.warning('请选择物品名称');
					this.$store.state.loading = false;
					return;
				}
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					wpids: this.vwpid,
					note: this.vnote,
					// lyckid: this.vlyckid,
					yhid: logininfo.id,
					xxid:logininfo.xxid
				});
				//执行
				this.axios.post(this.$store.state.api + 'wppdmx/insert', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', { type: 'add', cancel: false });
							this.$store.state.loading = false;
						} else {
						this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.warning("服务器繁忙，请重试");
						this.$store.state.loading = false;
					})
			},
        cancel() {
				this.$emit('close', { type: 'add', cancel: true })
			},
				componentsShow (type,data) { //显示组件
						console.log(type,data)
						for ( let i in this.portComponents ) {
								if (type == this.portComponents[i].type) {
										console.log(this.portComponents[i])

										this.portComponents[i].toggle = true;
										this.portComponents[i].params = data;

										if (this.portComponents[i].data.type == 'single') {
												this.portComponents[i].data.index = data.row.id

										}else if(this.portComponents[i].data.type == 'multiple'){
												this.portComponents[i].data.index = this.multipleDelNum;

										}else{
												return;
										}
										return;
								}
						}

				},
				componentsHide (setting) { //关闭组件
					console.log()
						if(setting.data){
							let strID = [];
		                    setting.data.forEach(function(v,i){
		                       strID.push(v.id)
		                    })
		                    this.vwpid = strID.join(",");
		                    let strMC = [];
		                    setting.data.forEach(function(v,i){
		                       strMC.push(v.mc)
		                    })
		                    this.vwpidmc = strMC.join(",");
//								this.vwpidmc = setting.data[0].mc
//								this.vwpid = setting.data[0].id
								// this.vje = setting.data[0].jg
								for ( let i in this.portComponents ) {
										if (setting.type == this.portComponents[i].type) {
												this.portComponents[i].toggle = false;
												if (this.portComponents[i].type == 'singleDelete') {
														this.dataList.splice(setting.index,1)
												}
												if (!setting.cancel) {
													 // this.search();
														if (setting.type == "student") {
																this.student = setting.data.zwm + ' - ' + setting.data.xh
																this.studentid = setting.data.id
														}else{

																setting.data.forEach( (v) => {

														 var iscan =true;
														 for ( let z in this.dataList ) {
															console.log(z,v.id );
															if(this.dataList[z].id==v.id){
																iscan =false;
																break;
															}
														 }
							if (iscan){
															 // this.dataList.push(v);
															}
														})
														}
												}
												return;
										}
								}
						}else{
							for ( let i in this.portComponents ) {
			                    if (setting.type == this.portComponents[i].type) {
			                        this.portComponents[i].toggle = false;
			                        if (!setting.cancel) {

			                        }
			                        return;
			                    }
			                }
						}

						}
							}
	}
</script>
<style lang="less" scoped>
	.wrap {
		.input-block {
			margin-bottom: 20px;
			text-align: center;
		}
		.bt{
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		color:white;
		text-align:left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}
	.form {
	text-align: left;
}
		.input {
			width:80%;
			display: inline-block;
		}
		.input1 {
			width:90%;
			display: inline-block;
		}
		.input-block{
			vertical-align: middle;
		}
		.input-block span {
			display: inline-block;
			width: 16%;
			text-align: right;
		}
		.submit {
			width: 120px;
		}
	    .wpfl{
			background: #fff;
			position: absolute;
			top: 5px;
			right: -15%;
		}
	}
</style>
